/**
 * Created by python on 19-2-28.
 */

// .catch(error =>{});



let app = new Vue({
    el:"#app",
    data:{

        // 页面中需要使用到的数据，键值对
        user_id: localStorage.user_id || sessionStorage.user_id,
        token: localStorage.token || sessionStorage.token,
        act: null,
        now: 0,
        endline: 0,
        last_time: 0,
        history_title: ''
    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        let activity_id = get_query_string('id', 1);
        // console.log(activity_id);
        axios.get(HOST+'/activity/'+ activity_id)
            .then(response=>{
                this.act = response.data;
                console.log(response.data.name)
                if (this.user_id) {
                    axios.post(HOST+'/browse_histories/', {
                        history_title: response.data.name,
                        history_address: window.location.href
                    }, {
                        headers: {
                            'Authorization': 'JWT ' + this.token
                        }
                    })
                }
                // 获取当前时间 获取截止时间
                let server_time = response.headers.date;
                this.now = Math.floor(new Date(server_time).getTime()/1000);
                this.endline = Math.floor(new Date(response.data.end_line).getTime()/1000);
                setInterval(()=>{
                    this.now += 1;
                    this.last_time = this.endline - this.now;
                },1000)

        });


    },
    methods:{
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
    },
    computed:{
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    },
    filters: {
        sec: function (value) {
            let day = Math.floor(value / (60*60*24));
            let hour = Math.floor(value % (60*60*24) / (60*60));
            let minute = Math.floor(value % (60*60) / 60) ;
            let second = value % 60 ;
            return day + "天" + hour + "时" + minute + "分" + second + "秒"
        }
    }
});